from flask_wtf import FlaskForm
from wtforms import *
from wtforms.validators import *
from flask import g
class LoginForm(FlaskForm):

    username = StringField(validators=[required(message='请输入用户名'),length(max=50,min=1,message='用户名不存在')])
    password = StringField(validators=[required(message='请输入密码'),length(max=16,min=6,message='密码错误')])



class MessageForm(FlaskForm):

    title = StringField(validators=[required(message='请输入标题'),length(max=18,min=6,message='请输入长度为6~18的标题')])


class EditMessageForm(FlaskForm):

    title = StringField(validators=[required(message='请输入标题'),length(max=300,min=0,message='长度在0~300')])
    types = StringField(validators=[required(message='请输入选择的对象')])
    sendtype = StringField(validators=[required(message='请输入发送的类型')])
    content = StringField(validators=[])
    status = IntegerField(validators=[required(message='请输入状态')])
    max_number = IntegerField(validators=[required(message='请输入最大发送数量')])
    wx_name = StringField(validators=[])
    wx_number = StringField(validators=[])

class ChangePWDForm(FlaskForm):

    new = StringField(validators=[required('请输入新密码'),length(max=18,min=8,message='新密码长度需在8~18之间')])
    new1 = StringField(validators=[required('请重复密码'),EqualTo('new',message='两次密码输入不一致'),length(max=18,min=8,message='新密码长度需在8~18之间')])
    old = StringField(validators=[required('请输入旧密码'),length(max=18,min=8,message='旧密码错误')])

    # def validate_old(self,data):
    #     data = data.data
    #
    #     if not g.user.checkPassWord(data):
    #         raise ValidationError('旧密码错误')
